package com.example.utils;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.Rotate;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;


public class FragmentWithBundle extends Fragment {

    public Bundle bundle;
    public ImageView imageView;
    public FragmentWithBundle(Bundle bundle){
        this.bundle = bundle;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.fragment_with_bundle, container, false);
        TextView textView = view.findViewById(R.id.a);
        imageView = view.findViewById(R.id.imageView);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle q = FragmentWithBundle.this.getArguments();
                String a = q.getString("a");
                Log.d("TAG", "onClick: "+a);

                DrawableCrossFadeFactory fadeFactory = new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build();
                RequestOptions requestOptions = new RequestOptions()
                        .error(R.drawable.error)
                        .override(1000,1000);
                Glide.with(getContext()).load("https://tse1-mm.cn.bing.net/th?id=OIP.rGOI2_UB7WoEMs7hN_ZGvQAAAA&w=145&h=160&c=8&rs=1&qlt=90&pid=3.1&rm=2").apply(requestOptions)
                        .transition(DrawableTransitionOptions.withCrossFade(2000))
                        //设置圆角
                        .transform(new Rotate(20))

                        .into(imageView);
            }
        });
        return  view;
    }

}